import { Table } from 'antd';
import { ContractManageAPI } from '../common/type';
import Cls from 'classnames';
import { ConractControllerContext, IContractsActionEnum } from '../common';
import { useContext, useMemo } from 'react';
import { openPartyColumns } from '../mconfig';
export const UpdateFirstPartyTableView: React.FC<ContractManageAPI.IUpdateFirstPartyTableView> = ({ openSubjectModal }) => {
  /** 引入上下文 */
  const { pageType, partyFirstSelectRows, contractDispatch, contractForm } = useContext(ConractControllerContext);

  const delSelectRow = () => {
    contractDispatch({
      type: IContractsActionEnum.SELECT_PARTYALIST,
      payload: [],
    });

    contractForm?.setFieldsValue({
      oppositeName: null,
      oppositeID: null,
      creditID: null,
      bankName: null,
      bankAccount: null,
      registerPhone: null,
      workAddress: null,
    });
  };

  /** 表格行配置 */
  const columns: Record<string, any>[] = useMemo(() => {
    return openPartyColumns(openSubjectModal, delSelectRow, pageType);
  }, [partyFirstSelectRows]);

  return (
    <div className={Cls('list-table', 'descriptionsType-tableSty')}>
      <Table
        bordered
        size="small"
        dataSource={partyFirstSelectRows}
        columns={columns}
        rowKey={(res) => res?.partyId}
        scroll={{ x: 1200, y: '' }}
        pagination={false}
      />
    </div>
  );
};
